package com.example.springboot.controller;

import com.example.springboot.common.AuthAccess;
import com.example.springboot.common.Result;
import com.example.springboot.entity.CityPopulation;
import com.example.springboot.entity.EthnicPopulation;
import com.example.springboot.entity.PopulationStatistics;
import com.example.springboot.service.CitypopulationService;
import com.example.springboot.service.EthnicPopulationService;
import com.example.springboot.service.PopulationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 功能：人口数据接口
 * 作者：陈雷
 * 日期：2024/11/10 15:23
 */
@RestController
@CrossOrigin
@RequestMapping("/population")
public class PopulationController {

    @Autowired
    PopulationService populationService;
    @Autowired
    CitypopulationService citypopulationService;
    @Autowired
    EthnicPopulationService ethnicPopulationService;


//    查询2022年度，出生率，死亡率，自然增长率，总人口
    @RequestMapping("/select2022")
    public Result select2022(){
        List<PopulationStatistics> result = populationService.select2022();
        System.out.println("Returning data for /select2022: " + result);
        return Result.success(result);
    }

//    查询所有年份
    @AuthAccess
    @RequestMapping("/selectAllYear")
    public Result selectAllYear(){
        List<PopulationStatistics> result = populationService.selectAllYear();
        return Result.success(result);
    }

    // 查询所有市区人口总数2022年

    @AuthAccess
    @RequestMapping("/selectByCity")
    public Result selectByCity(){
        List<CityPopulation> result = citypopulationService.selectByCity();
        return Result.success(result);
    }

    // 查询所有民族人口总数2022年
    @AuthAccess
    @RequestMapping("/selectByEthnic2022")
    public Result selectByEthnic2022(){
        List<EthnicPopulation> result = ethnicPopulationService.selectByEthnic2022();
        System.out.println("Returning data for /selectByEthnic2022: " + result);
        return Result.success(result);
    }

//    查询所有民族人口总数
    @AuthAccess
    @RequestMapping("/selectByEthnicAll")
    public Result selectByEthnicAll(){
        List<EthnicPopulation> result = ethnicPopulationService.selectByEthnicAll();
        return Result.success(result);
    }




}